package com.baseweb.webadmin.weixin.sign;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.baseweb.webadmin.weixin.utils.Constant;
import com.baseweb.webadmin.weixin.utils.MD5Util;

/**
 * 支付签名算法
 * @author wcc
 *
 */
public class PaySign {
	/**
	 * 签名算法
	 */
	public  static String createSign(Map<String, String> params) {

		StringBuffer sb = new StringBuffer();

		Set es = params.entrySet();

		Iterator it = es.iterator();

		while (it.hasNext()) {

			Map.Entry entry = (Map.Entry) it.next();

			String k = (String) entry.getKey();

			String v = (String) entry.getValue();

			if (null != v && !"".equals(v)

			&& !"sign".equals(k) && !"key".equals(k)) {

				sb.append(k + "=" + v + "&");

			}
		}
		sb.append("key=" + Constant.WX_API);
		String sign = MD5Util.MD5Encode(sb.toString(), Constant.SIGN_ENCODE).toUpperCase();
		return sign;
	}
}
